import 'package:bxultimate/data/request/user_request.dart';
import 'package:bxultimate/data/store/auth_store.dart';
import 'package:bxultimate/domain/user/ThreeLoginDto.dart';
import 'package:bxultimate/shared/shared.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'state.dart';

class UserAccountIndexController extends GetxController {
  final UserAccountIndexState state = UserAccountIndexState();
final TextEditingController emailController = TextEditingController();
  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();

    getData();
  }

  void getData() async {
    // 第三方登录
    List<ThreeLoginDto> threeLogin = await UserRequest.getThreeLogin();
    if (threeLogin.length > 0) {
      state.wechatName = threeLogin[0].username!;
    }
  }

  void accountCancel() {
    showGeneralDialog(
      context: Get.context!,
      pageBuilder: (BuildContext buildContext, Animation<double> animation,
          Animation<double> secondaryAnimation) {
        return TDInputDialog(
          textEditingController: emailController,
          title: '确认注销账号？',
          content: '注销账号后，账号下的所有数据将被清除，且不可恢复。',
          hintText: '请填写您的邮箱',
          rightBtn: TDDialogButtonOptions(title: '确认', action: () {
            if(!UtilValidate.checkIsEmail(emailController.text)){
              return SmartDialog.showToast('邮箱格式不正确');
            }

            SmartDialog.showToast('您的申请已提交！');
            Get.back();
          }),
        );
      },
    );
  }
}
